// import 'package:flutter/material.dart';
import 'package:flutter/material.dart';
import 'package:ls_work/res/gaps.dart';
import 'package:oktoast/oktoast.dart';

/// Toast工具类
class Toast {
  static show(String msg, {duration = 2000}) {
    showToast(
      msg,
      position: ToastPosition(),
      duration: Duration(milliseconds: duration),
      dismissOtherToast: true,
    );
  }

  static showStateWithMsg(String msg, {int? seconds}) {
    showToastWidget(
      Container(
        color: Colors.black.withOpacity(0.5),
        width: 130,
        height: 130,
        alignment: Alignment.center,
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          crossAxisAlignment: CrossAxisAlignment.center,
          children: [
            CircularProgressIndicator(),
            Gaps.vGap15,
            Text(
              msg ?? '正在加载',
              style: TextStyle(color: Colors.white, fontSize: 14),
            ),
          ],
        ),
      ),
      duration: Duration(seconds: seconds ?? 15),
      position: ToastPosition(),
      dismissOtherToast: true,
    );
  }

  static showSuccessWithMsg(String msg, {int? seconds}) {
    showToastWidget(
      Container(
        color: Colors.black.withOpacity(0.5),
        width: 130,
        height: 130,
        alignment: Alignment.center,
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          crossAxisAlignment: CrossAxisAlignment.center,
          children: [
            Icon(
              Icons.done,
              color: Colors.blue,
              size: 50,
            ),
            Gaps.vGap15,
            Text(
              msg ?? '正在加载',
              style: TextStyle(color: Colors.white, fontSize: 14),
            ),
          ],
        ),
      ),
      position: ToastPosition(),
      dismissOtherToast: true,
    );
  }

  static cancelToast() {
    dismissAllToast();
  }
}
